﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LibraryModels;

namespace WebAppLibrary
{
    /// <summary>
    /// Login  Class
    /// Leo.wl
    /// 2010-05-12
    /// </summary>
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 登录系统
        /// Handles the Click event of the btnLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            if (this.txtName.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入用户名!')</script>");
            }
            else if (this.txtPass.Text.Trim() == "")
            {
                Response.Write("<script>alert('请输入密码!')</script>");
            }
            else
            {
                LibraryModels.TabUser MyUserInfo = new TabUser();
                MyUserInfo.UserName = this.txtName.Text.Trim();
                MyUserInfo.UserPass = this.txtPass.Text.Trim();
                bool bol = LibraryDALFactory.DataAccess.CreateTabUser().GetLogin(MyUserInfo);
                if (bol)
                {
                    Session["LoginName"] = this.txtName.Text.Trim();
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Response.Write("<script>alert('用户名或密码错误!')</script>");
                }
                
            }

        }

        /// <summary>
        /// 取消登录
        /// Handles the Click event of the btnOut control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void btnOut_Click(object sender, ImageClickEventArgs e)
        {
            this.txtName.Text = string.Empty;
            this.txtPass.Text = string.Empty;
        }
    }
}
